﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DotNetNuke.Knockout;

public partial class _Default : System.Web.UI.Page
{
    private string _viewModel;
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        cbEnabled.InputAttributes.Add("data-bind", "checked: Enabled");

        var user = new UserInfo()
        {
            Username = "Jack Smith",
            FirstName = "Jack",
            LastName = "Smith",
            Enabled = true,
            Childrens = new List<UserInfo>()
        };

        user.Childrens.Add(new UserInfo()
        {
            Username = "Lily Smith",
            FirstName = "Lily",
            LastName = "Smith"
        });

        user.Childrens.Add(new UserInfo()
        {
            Username = "Kity Smith",
            FirstName = "Kity",
            LastName = "Smith"
        });

        _viewModel = new KnockoutSerializer().Serialize(user);

        if (!string.IsNullOrEmpty(Request.QueryString.ToString()))
        {
            var newUser = new KnockoutSerializer().Deserialize<UserInfo>(System.Web.HttpUtility.UrlDecode(Request.QueryString.ToString()));
            Response.Clear();
            Response.Write(newUser.Username);
            Response.End();
        }
    }

    public string ViewModel
    {
        get { return _viewModel; }
    }
}